package com.liwen.web.controller.page;

import com.liwen.api.vo.OrderVO;
import com.liwen.dao.entity.OrderEntity;
import com.liwen.service.coop.jd.JDService;
import com.liwen.service.depend.OrderService;
import com.liwen.service.exception.BizException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

@Controller
public class WelcomeController {

    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Value("${app.application.name}")
    private String message;

    @Resource
    private OrderService orderService;

    @Resource
    private JDService jdService;

    @GetMapping("/")
    public String index(Map<String, Object> model) {
        return "index";
    }


    @GetMapping("/welcome")
    public String welcome(Map<String, Object> model) {
        int insId = 51;
        String sn = "1180827713227803";
        OrderEntity order = orderService.bysn(insId, sn);
        log.info("idcard:" + order.getIdCard());
        jdService.testJD();//测试多线程

        model.put("time", new Date());
        model.put("message", this.message);
        return "welcome";
    }

    @GetMapping("/testPageException")
    public String testPageException(Map<String, Object> model) {
        test();
        model.put("time", new Date());
        model.put("message", this.message);
        return "welcome";
    }

    private void test() {
        throw new BizException("自定义异常");
    }

}
